package org.itsky.study.test4;

import java.io.PipedReader;

/**
 * @Author sky
 * @Site cmtianxie163.com 2020/4/16 11:08
 */
class TicketRunnable implements Runnable{
    /**
     * 使用该类对象为参数 调用Thread构造函数 创建对象时 用的时同一个对象 所有不用加static
     *
     * 存在线程安全问题
     */

    private int ticket = 100;
    @Override
    public void run() {
        while (true){
            if (ticket > 0){
                System.out.println(Thread.currentThread().getName() +"正在售票，票号为 " + (101-ticket));
                ticket --;
            }else{
                break;
            }
        }
    }
}


public class TicketTest2 {
    public static void main(String[] args) {
        TicketRunnable tr = new TicketRunnable();

        Thread t1 = new Thread(tr);
        Thread t2 = new Thread(tr);
        Thread t3 = new Thread(tr);

        t1.setName("窗口1");
        t2.setName("窗口2");
        t3.setName("窗口3");

        t1.start();
        t2.start();
        t3.start();

    }

}
